<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>path.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_graphics_ext_path.js.html">path.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2007 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview A thick wrapper around paths.
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.graphics.ext.Path&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.array&#39;);
<a name="line24"></a>goog.require(&#39;goog.graphics.AffineTransform&#39;);
<a name="line25"></a>goog.require(&#39;goog.graphics.Path&#39;);
<a name="line26"></a>goog.require(&#39;goog.math&#39;);
<a name="line27"></a>goog.require(&#39;goog.math.Rect&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Creates a path object
<a name="line32"></a> * @constructor
<a name="line33"></a> * @extends {goog.graphics.Path}
<a name="line34"></a> */
<a name="line35"></a>goog.graphics.ext.Path = function() {
<a name="line36"></a>  goog.graphics.Path.call(this);
<a name="line37"></a>};
<a name="line38"></a>goog.inherits(goog.graphics.ext.Path, goog.graphics.Path);
<a name="line39"></a>
<a name="line40"></a>
<a name="line41"></a>/**
<a name="line42"></a> * Optional cached or user specified bounding box.  A user may wish to
<a name="line43"></a> * precompute a bounding box to save time and include more accurate
<a name="line44"></a> * computations.
<a name="line45"></a> * @type {goog.math.Rect?}
<a name="line46"></a> * @private
<a name="line47"></a> */
<a name="line48"></a>goog.graphics.ext.Path.prototype.bounds_ = null;
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * Clones the path.
<a name="line53"></a> * @return {goog.graphics.ext.Path} A clone of this path.
<a name="line54"></a> */
<a name="line55"></a>goog.graphics.ext.Path.prototype.clone = function() {
<a name="line56"></a>  var output = /** @type {goog.graphics.ext.Path} */
<a name="line57"></a>      (goog.graphics.ext.Path.superClass_.clone.call(this));
<a name="line58"></a>  output.bounds_ = this.bounds_ &amp;&amp; this.bounds_.clone();
<a name="line59"></a>  return output;
<a name="line60"></a>};
<a name="line61"></a>
<a name="line62"></a>
<a name="line63"></a>/**
<a name="line64"></a> * Transforms the path. Only simple paths are transformable. Attempting
<a name="line65"></a> * to transform a non-simple path will throw an error.
<a name="line66"></a> * @param {!goog.graphics.AffineTransform} tx The transformation to perform.
<a name="line67"></a> * @return {goog.graphics.ext.Path} The path itself.
<a name="line68"></a> */
<a name="line69"></a>goog.graphics.ext.Path.prototype.transform = function(tx) {
<a name="line70"></a>  goog.graphics.ext.Path.superClass_.transform.call(this, tx);
<a name="line71"></a>
<a name="line72"></a>  // Make sure the precomputed bounds are cleared when the path is transformed.
<a name="line73"></a>  this.bounds_ = null;
<a name="line74"></a>
<a name="line75"></a>  return this;
<a name="line76"></a>};
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>/**
<a name="line80"></a> * Modify the bounding box of the path.  This may cause the path to be
<a name="line81"></a> * simplified (i.e. arcs converted to curves) as a side-effect.
<a name="line82"></a> * @param {number} deltaX How far to translate the x coordinates.
<a name="line83"></a> * @param {number} deltaY How far to translate the y coordinates.
<a name="line84"></a> * @param {number} xFactor After translation, all x coordinates are multiplied
<a name="line85"></a> *     by this number.
<a name="line86"></a> * @param {number} yFactor After translation, all y coordinates are multiplied
<a name="line87"></a> *     by this number.
<a name="line88"></a> * @return {goog.graphics.ext.Path} The path itself.
<a name="line89"></a> */
<a name="line90"></a>goog.graphics.ext.Path.prototype.modifyBounds = function(deltaX, deltaY,
<a name="line91"></a>    xFactor, yFactor) {
<a name="line92"></a>  if (!this.isSimple()) {
<a name="line93"></a>    var simple = goog.graphics.Path.createSimplifiedPath(this);
<a name="line94"></a>    this.clear();
<a name="line95"></a>    this.appendPath(simple);
<a name="line96"></a>  }
<a name="line97"></a>
<a name="line98"></a>  return this.transform(goog.graphics.AffineTransform.getScaleInstance(
<a name="line99"></a>      xFactor, yFactor).translate(deltaX, deltaY));
<a name="line100"></a>};
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/**
<a name="line104"></a> * Set the precomputed bounds.
<a name="line105"></a> * @param {goog.math.Rect?} bounds The bounds to use, or set to null to clear
<a name="line106"></a> *     and recompute on the next call to getBoundingBox.
<a name="line107"></a> */
<a name="line108"></a>goog.graphics.ext.Path.prototype.useBoundingBox = function(bounds) {
<a name="line109"></a>  this.bounds_ = bounds &amp;&amp; bounds.clone();
<a name="line110"></a>};
<a name="line111"></a>
<a name="line112"></a>
<a name="line113"></a>/**
<a name="line114"></a> * @return {goog.math.Rect?} The bounding box of the path, or null if the
<a name="line115"></a> *     path is empty.
<a name="line116"></a> */
<a name="line117"></a>goog.graphics.ext.Path.prototype.getBoundingBox = function() {
<a name="line118"></a>  if (!this.bounds_ &amp;&amp; !this.isEmpty()) {
<a name="line119"></a>    var minY;
<a name="line120"></a>    var minX = minY = Number.POSITIVE_INFINITY;
<a name="line121"></a>    var maxY;
<a name="line122"></a>    var maxX = maxY = Number.NEGATIVE_INFINITY;
<a name="line123"></a>
<a name="line124"></a>    var simplePath = this.isSimple() ? this :
<a name="line125"></a>        goog.graphics.Path.createSimplifiedPath(this);
<a name="line126"></a>    simplePath.forEachSegment(function(type, points) {
<a name="line127"></a>      for (var i = 0, len = points.length; i &lt; len; i += 2) {
<a name="line128"></a>        minX = Math.min(minX, points[i]);
<a name="line129"></a>        maxX = Math.max(maxX, points[i]);
<a name="line130"></a>        minY = Math.min(minY, points[i + 1]);
<a name="line131"></a>        maxY = Math.max(maxY, points[i + 1]);
<a name="line132"></a>      }
<a name="line133"></a>    });
<a name="line134"></a>
<a name="line135"></a>    this.bounds_ = new goog.math.Rect(minX, minY, maxX - minX, maxY - minY);
<a name="line136"></a>  }
<a name="line137"></a>
<a name="line138"></a>  return this.bounds_;
<a name="line139"></a>};
</pre>


</body>
</html>
